using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace MyGame
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Background : Microsoft.Xna.Framework.DrawableGameComponent
    {
        public Texture2D Texture1;
        public Texture2D Texture2;

        private Vector2 posBack1;
        private Vector2 posBack2;

        protected GraphicsDevice device;
        protected SpriteBatch spriteBatch;

        public Background(Game game)
            : base(game)
        {
            // TODO: Construct any child components here
            device = GameGlobals.graphicsManager.GraphicsDevice;
            spriteBatch = new SpriteBatch(device);
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here
            posBack1.Y = 0;
            posBack2.Y = -800;

            base.Initialize();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            posBack1.Y += GameGlobals.backgroundVelocity;
            posBack2.Y += GameGlobals.backgroundVelocity;

            if (posBack1.Y >= 800)
            {
                posBack1.Y = -800 + (posBack1.Y - 800);
            }
            else if (posBack2.Y >= 800)
            {
                posBack2.Y = -800 + (posBack2.Y - 800);
            }

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin();
            spriteBatch.Draw(Texture1, posBack1, Color.White);
            spriteBatch.Draw(Texture2, posBack2, Color.White);
            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
